//
//  LGFBadgeView.swift
//  EWEMdt3
//
//  Created by 来 on 2020/4/2.
//  Copyright © 2020 laiguofeng. All rights reserved.
//

import UIKit

class LGFBadgeView: UIView {
    
    var label: UILabel!
    var text: String! {
        didSet {
            if label != nil {
                label.text = Int(text)! > 99 ? "99+" : text
                self.isHidden = (label.text?.count == 0 || label.text == "0")
            }
        }
    }
    var fontSize: CGFloat!
    
    override init(frame: CGRect) {
        super.init(frame: frame)
    }
    
    required init(_ color: String, _ text: String, _ fontSize: CGFloat) {
        super.init(frame: .zero)
        self.text = text
        self.fontSize = fontSize
        isHidden = true
        backgroundColor = UIColor.init(lgf_HexString: color)
        configUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func configUI() {
        layer.cornerRadius = 8
        
        label = UILabel.init()
        label.text = self.text
        label.textAlignment = .center
        label.textColor = EWEDarkMode.white()
        label.font = UIFont.boldSystemFont(ofSize: fontSize)
        addSubview(label)
        label.snp.makeConstraints { (make) in
            make.edges.equalToSuperview().inset(UIEdgeInsets.init(top: 2, left: 3.5, bottom: 2, right: 3.5))
        }
        
    }
    
}
